package com.medical.medical.controller.qinxuController;
import com.github.pagehelper.PageInfo;
import com.medical.medical.entity.Notice;
import com.medical.medical.service.NoticeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;

/**
 * @ClassName NoticeController
 * @Description 坤坤最帅 - 坤坤最美!
 * @Author QinXu
 * @Date 2022/9/14 10:05
 * @Version 1.0
 */
@RequestMapping("/notice")
@Controller
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    /*
     * @description: 点击进入系统公告页面.并查询所有公告
     * @author: qin
     * No such property: code for class: Script1
     * @return:
     * @time: 2022/9/14 10:11
     */
    @RequestMapping(value = {"/enterNotice/{pageNum}"})
    public String enterNotice(Model model,
                              @PathVariable(value = "pageNum",required = false) Integer pageNum){
        if (pageNum==null){
            pageNum=1;
        }
        PageInfo<Notice> noticeList =  noticeService.getAllNotice(pageNum);
        model.addAttribute("noticeList",noticeList);
        return "notice";
    }
    /*
     * @description: 模糊查询公告
     * @author: qin
     * No such property: code for class: Script1
     * @return:
     * @time: 2022/9/17 10:13
     */
    @RequestMapping(value = {"/vague/enterNotice"})
    public String likeNotice( Integer pageNum,
                              String noticeName,
                              Model model){
        if(pageNum==null){
            pageNum=1;
        }
        PageInfo<Notice> noticeList  = noticeService.getNoticeByNoticeName(pageNum,noticeName);
        model.addAttribute("noticeList",noticeList);
        return "notice";
    }
    /*
     * @description: 根据id删除公告
     * @author: qin
     * No such property: code for class: Script1
     * @return:
     * @time: 2022/9/24 11:59
     */
    @RequestMapping(value = {"/delete/{noticeId}"})
    public String deleteNotice(@PathVariable(value = "noticeId") String noticeId,
                               Model model){
        int result = noticeService.deleteById(noticeId);
        model.addAttribute("result",result);
        return "redirect:/notice/enterNotice/1";
    }

    /*
     * @author: qin
     * @description: 进入公告添加页面
     * No such property: code for class: Script1
     * @return:
     * @time: 2022/9/24 12:16
     */
    @RequestMapping("/jr")
    public String j(){
        return "addnotice";
    }
    /*
     * @description: 添加公告
     * @author: qin
     * No such property: code for class: Script1
     * @return:
     * @time: 2022/9/24 11:59
     */
    @RequestMapping("/add/notice")
    public String addNotice(Notice notice){
        int result = noticeService.addNotice(notice);
        return "redirect:/notice/enterNotice/1";
    }

}
